<%@ page contentType="text/html; charset=UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>

<jsp:include page="header-sidebar.jsp">
    <jsp:param name="title" value="Feed"/>
</jsp:include>

<div id="content">
    <div id="shadow">
        <a href="validateJoinFeedUser.action" target="_blank">
            <div id="pdf-download">
                <img src="img/Oficina-PDF-icon.png"/>
                <h3>Download PDF</h3>
                <p>Danh sách feed phổ biến</p>
            </div></a>
        <h2 class="homeTitle">Feed</h2>

        <div id="notify">
            <font color="green"><h3>${requestScope.notify}</h3></font>
        </div>

        <c:import url="../WEB-INF/dataXML/feed.xml" var="xmlDoc" charEncoding="UTF-8"/>
        <c:import url="../WEB-INF/xsl/feedManagement.xsl" var="xslDoc" charEncoding="UTF-8"/>
        <x:transform xml="${xmlDoc}" xslt="${xslDoc}"/>

        <b id="content-after"></b> </div>
</div>

<script type="text/javascript" src="../js/jsUtils.js"></script>
<script type="text/javascript">
    setTimeout(function(){
        document.getElementById("notify").hidden = true;
    }, 2*1000);

    activeCurrentNav("feedNav");

    function confirmDelete(form) {
        if (confirm("Bạn thật sự muốn xóa feed này? ")) {
            form.submit();
            return true;
        }
        return false;
    }

    function validateRegEx(regex, input, helpText, helpMessage) {
        if (!regex.test(input)) {
            if (helpText != null) {
                helpText.innerHTML = helpMessage;
            }
            return false;
        } else {
            if (helpText != null) {
                helpText.innerHTML = "";
            }
            return true;
        }
    }

    function validateNonEmpty(inputField, helpText) {
        return validateRegEx(/^[\S]+/, inputField.value, helpText, "Ký tự đầu tiên phải khác khoảng trắng.");
    }

    function validateLength(minLength, maxLength, inputField, helpText) {
        return validateRegEx(new RegExp("^.{" + minLength + "," + maxLength + "}$"),
        inputField.value, helpText, "Chỉ được nhập từ " + minLength + " tới " + maxLength + " ký tự");
    }

    function check(minLength, maxLength, inputField, helpText) {
        if (validateNonEmpty(inputField, helpText)) {
            validateLength(minLength, maxLength, inputField, helpText)
        }
    }

    function validateSubmit(form) {
        if (validateNonEmpty(form["title"], form["title_help"]) &&
            validateNonEmpty(form["description"], form["description_help"]) &&
            validateLength(1, 50, form["title"], form["title_help"]) &&
            validateLength(1, 100, form["description"], form["description_help"])) {
            form.submit;
            return true;
        } else {
            alert("Nội dung không phù hợp. Xin kiểm tra lại.");
            return false;
        }
    }
</script>

<jsp:include page="footer.jsp"/>